<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Address
 *
 * @property int $id
 * @property int $user_id
 * @property string $contact_name
 * @property string $contact_phone
 * @property string $province
 * @property string $city
 * @property string $district
 * @property string $address
 * @property int $is_default
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $full_address
 * @property-read \App\Models\User $user
 * @method static \Database\Factories\AddressFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|Address newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Address newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Address query()
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereContactName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereContactPhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereDistrict($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereIsDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereUserId($value)
 * @mixin \Eloquent
 * @property string|null $id_code
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereIdCode($value)
 * @property string|null $id_name
 * @method static \Illuminate\Database\Eloquent\Builder|Address whereIdName($value)
 */
class Address extends Model
{
    use HasFactory;
	
	protected $guarded = ['id'];
	
	public function getFullAddressAttribute()
	{
		$province = isset(config('areas')[$this->province]) ? config('areas')[$this->province] : '';
		$city = isset(config('areas')[$this->city]) ? config('areas')[$this->city] : '';
		$district = isset(config('areas')[$this->district]) ? config('areas')[$this->district] : '';
		
		return "{$province} {$city} {$district} {$this->address}";
	}
	
	public function user()
	{
		return $this->belongsTo(User::class);
	}
}
